<!-- 模板继承 -->
{extend name="public:base" /}

<!-- 页面标题 -->
{block name="title"}Administrator{/block}

<!-- 自定义css -->
{block name="css"}{/block}

<!-- 内容区域 -->
{block name="content"}
  <div class="nav-tabs-custom">
    <ul class="nav nav-tabs">
      <li class="active"><a href="#">{:lang('Hooks')}</a></li>
      <li class=""><a href="{:url('admin/hooks/create')}">{:lang('Create')}</a></li>
    </ul>

    <div class="tab-content">
        <div class="tab-pane active table-responsive no-padding">
            <table class="table table-condensed table-hover">
                <thead>
                    <tr>
                        <th>#ID</th>
                        <th>{:lang('Title')}</th>
                        <th>{:lang('Description')}</th>
                        <th>{:lang('Type')}</th>
                        <th>{:lang('Action')}</th>
                    </tr>
                </thead>
                <tbody>
                    {volist name="list" id="vo"}
                    <tr id = "tr_{$vo.id}">
                        <td>{$vo.id}</td>
                        <td>{$vo.name}</td>
                        <td>{$vo.description}</td>
                        <td>
                            {switch vo.type}
                                {case 1}控制器{/case}
                                {case 2}视图{/case}
                                {default /}
                            {/switch}
                        </td>
                        <td>
                            <a href="{:url('admin/hooks/edit', ['id' => $vo['id']])}"> {:lang('Edit')}</a>
                            <a onclick="remove('{$vo.id}');" href="#"> {:lang('Delete')}</a>
                        </td>
                    </tr>
                    {/volist}

                    {empty name="list"}
                    <tr>
                        <td colspan="8" class="text-center">{:lang("No record")}</td>
                    </tr>
                    {/empty}
                </tbody>
            </table>
        </div>
        <!-- /.tab-pane -->
    </div>
    <!-- /.tab-content -->
    <div class="box-footer">
        <div class="row">
          <div class="col-md-6">

          </div>
          <div class="col-md-6">
            <div class="text-right"> {$page} </div>
          </div>
        </div>
    </div>
  </div>


{/block}

<!-- 自定义js -->
{block name="js"}
<script type="text/javascript">
    function remove(id){
        swal({
          title: "{:lang('Are you sure')}",
          type: 'warning',
          showCancelButton: true,
          confirmButtonColor: '#3085d6',
          cancelButtonColor: '#d33',
          confirmButtonText: "{:lang('Yes')}",
          cancelButtonText: "{:lang('No')}",
        }).then(function(result){
              if (result.value) {
                $.ajax({
                    url:"{:Url('admin/hooks/remove')}",
                    data:{'id':id},
                    type:'post',
                    dataType:'json',
                    success: function(xhr){
                        if(xhr.code == 200){
                            swal(xhr.msg, "","success");
                            $("#tr_" + id).remove();
                        }else{
                            swal(xhr.msg, "", "error");
                        }
                    }
                })
              }
        })
    }
</script>
{/block}